﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IForm_ChooseFromList</summary>
    public class IForm_ChooseFromList : IForm
    {
        public int Choice; // Volba
        public string Caption; // Hlavny popis
        public string ChoiceNames; // Nazvy volieb
        public string ChoiceNotes; // Popisy volieb
        public char ChoiceSeparator; // Oddelovac

        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_Cancel;
        protected IAutoHeightLabel FLabel;
        protected ICommandLinkButtonsPanel FBtnsPanel;

        /// <summary>Konstruktor</summary>
        public IForm_ChooseFromList()
        {
        }

        /// <summary>Metoda OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowInTaskbar = false; MinimizeBox = MaximizeBox = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; // Inicializacia vlastnosti

            SetBounds(0, 0, 500, 500); System.Drawing.Size CS = ClientSize;

            FGrp = new IGroupBox(); // Vytvorim groupbox
            FBtn_Cancel = new IButton(lang.FORM_EDIT_CHOOSE_FROM_LIST_TEXT_1);

            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_Cancel }); // Zaradim

            IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50); // Umiestnim prvky do okna
            IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10);

            FLabel = new IAutoHeightLabel(Caption, FGrp.ClientSize.Width - 8);
            FBtnsPanel = new ICommandLinkButtonsPanel();

            FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel, FBtnsPanel }); // Zaradim

            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel, FGrp, 4, 16);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FBtnsPanel, FLabel, 0, 10); FBtnsPanel.Width = FLabel.Width; FBtnsPanel.Height = FGrp.ClientSize.Height - FBtnsPanel.Top - 4;

            FBtnsPanel.CreateButtons(ChoiceNames, ChoiceNotes, Choice, ChoiceSeparator); // Vytvorim tlacidla

            int H = FBtnsPanel.ControlShrinkValue; // Treba zmensit okno?
            if (H > 0)
            {
                FBtnsPanel.Height -= H; FGrp.Height -= H;
                FBtn_Cancel.Top -= H; Height -= H;
            }

            CancelButton = FBtn_Cancel;
            FBtnsPanel.ButtonClick += Event_PanelBtnClick;

            return true; // Vsetko OK
        }

        /// <summary>Event: Click pre tlacidlo 'OK'</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_PanelBtnClick(object pSender, EventArgs e)
        {
            Choice = FBtnsPanel.ClickedButtonIndex;
            DialogResult = System.Windows.Forms.DialogResult.OK; // Ukoncim dialog
        }
    }
}
